//商品列表
var app = getApp(); //全局APP
import { Items } from 'ItemModel.js';
var items = new Items();

Page({
  //页面的初始数据
  data: {
    id: '',
    showView: false,
    goodsList: [],
    //根路劲
    baseurl: 'https://wukongweixiu.cn/',
    minPrice: '',
    maxPrice:'',
    ajaxStatus: false,
    loading: true,
    loadingComplete: false,
    nodata:false,
    toView: "",
    where:"",
    searchData: {
      where: {},
      limit: 10,
      page: 1,
      order: {
        key:'id',
        sort:'desc'
      }
    }
  },

  //加载执行
  onLoad: function (options) {
    var where ='';
    
    if (options.id) {
      where = where+"cat_id="+ options.id
    }
    if (options.key) {
      where = where + "goods_name=" + options.key
      this.setData({
        where: options.key
      })
    }
   var that = this;
   that.setData({
     where:where
   })
    console.log(where)
   
    
    this.getGoods();
  },



  onChangeShowState: function () {
    var that = this;
    that.setData({
      showView: (!that.data.showView)
    })
  },



  

  

  //页面相关事件处理函数--监听用户下拉动作
  onPullDownRefresh: function () {
    // wx.showNavigationBarLoading()
    // setTimeout(function () {
    //   // complete
    //   wx.hideNavigationBarLoading() //完成停止加载
    //   wx.stopPullDownRefresh() //停止下拉刷新
    // }, 1500);
  },

  //页面上拉触底事件的处理函数
  // onReachBottom: function () {
  //   // console.log('加载更多');
  //   // setTimeout(() => {
  //   //   this.setData({
  //   //     isHideLoadMore: true,
        
  //   //   })
  //   // }, 1000)
  // },

  //跳转到商品详情页面
  goodsDetail: function (e) {
    wx.navigateTo({
      url: '../detail/detail?id=' + e.currentTarget.dataset.id
    });
  },

  //取得商品数据
  getGoods: function(){
    var page = this;
    var data = items.searchgoods(this.callBake,page.data.where);
  },

 
  callBake: function (res){
    console.log(res.data.data)
    var page = this;
    page.setData({
      goodsList: res.data.data,
    })
  },

  //上拉加载
  lower: function () {
    // var page = this;
    // page.setData({
    //   toView: 'loading'
    // });
    // if (!page.data.loadingComplete){
    //   page.setSearchData({
    //     page: page.data.searchData.page + 1
    //   });
      
    // }
  },

  //搜索
  // search: function (e) {
  //   var page = this;
  //   var key = e.detail.value;
  //   page.setSearchData({
  //     where: {
  //       search_name: key
  //     },
  //     page: 1
  //   }, true);
  //   page.getGoods();
  // },

  //跳转搜索
  searchNav: function () {
    wx.navigateTo({
      url: '../search/search'
    });
  }
});